var blackAndWhiteJs = function ($parent) {
	this.$parent = $parent;
	this.sysUtils = new kendoUtils();
	this.init();
	return this;
};

blackAndWhiteJs.prototype = {
		init : function () {
			var _this = this;
			var fieldArray = _this.sysUtils.getBindFieldArray(_this.$parent.find('.search-panel'));
			var functionArray = [
			                     {fName : 'search_btn' , fs : _this.findData},
			                     {fName : 'reset_btn' , fs : _this.resetInfo}
			                     ];
			_this.models = new bindBaseModel(null, fieldArray, functionArray, null);
			_this.sysUtils.bindDoucment(_this.models, _this.$parent, _this);
			Utils.createDataDictDropDownList({div:this.$parent.find("#dataType"), parentModelKey:BASIS.SPECIAL_TYPE.ROOT}, this);
			_this.initTable();
			_this.findData();
		},
		/*
		 * 重置按钮
		 */
		resetInfo:function(e){
			var that = $(e.target).data("that");
			that.sysUtils.setBindFieldNull(that.models.bindFieldArray);
		},
		initTable : function () {
			var _this = this;
			var columns = [
			               {
			            	   width : 30,
			            	   headerTemplate : '<input type="checkbox" gridId="black_white_data_list" onclick="gridCheckAll(this)" />',
			            	   template : '<input type="checkbox" name="blackWhiteId" value="${id}" />',
			               },
			               {
			            	   title : '车牌号',
			            	   field : 'vehicleNo'
			               },
			               {
			            	   title : '特殊名单类型',
			            	   template : '#:Utils.getModelNameByParentKey(BASIS.SPECIAL_TYPE.ROOT, dataType)#'
			               },
			               {
			            	   title : '是否占用车位',
			            	   template : '#:Utils.getModelNameByParentKey(BASIS.BOTT_LEVEL_ROOT.ROOT, takeUpSpaces)#'
			               },
			               {
			            	   title : '创建时间',
			            	   field : 'createTime'
			               },
			               {
			            	   title : '创建人',
			            	   field : 'createId'
			               }
			               ];
			var gridHeight = this.$parent.height() - this.$parent.find(".search-panel").outerHeight() - 1;
			_this.sysUtils.createGird(_this.$parent.find('#black_white_data_list'), {
				selectable : 'single',
				autoSync : true,
				height:gridHeight,
				columnMenu : true,
				pageable : {input : true, numeric : false},
				columns : columns,
				dataBound:function(){
						var tableList = _this.$parent.find("#black_white_data_list");
						tableList.find("tr:gt(0)").unbind("dblclick");
						tableList.find("tr:gt(0)").dblclick(function(e){
							var grid = tableList.data("kendoGrid");
							var dataItem = grid.dataItem(grid.select());
							//打开查看窗口
							_this.openEditWindow(dataItem["id"]);
					});	
				}
			});
		},
		findData : function (e) {
			var _this = this;
			if (!isEmpty(e)) {
				_this = $(e.target).data('that');
			}
			if (validityForm(_this.$parent)) {
				var grid = _this.$parent.find('#black_white_data_list').data('kendoGrid');
				var params = _this.sysUtils.getBindDocJson(_this.models.bindFieldArray);
				if(isNotEmpt(params["endTime"])){
					params["endTime"]  = kendo.toString(params["endTime"],'yyyy-MM-dd') + " 23:59:59";
				}
				var dataT = {'jsonParam' : JSON.stringify(params)};
				var dataSource = _this.sysUtils.getDataSource({url : baseApiPath + 'blackAndWhite/list', data : dataT, dataType : 'odata'});
				grid.setDataSource(dataSource);
			}
		},
		openNewWindow : function () {
			this.isEdit = false;
			this.openWindow('特殊名单新增');
		},
		openEditWindow : function (id) {
			var _this = this;
			JsonpAjax(baseApiPath + 'blackAndWhite/findSigngleById?id='+id, undefined, 'json', function (res) {
				_this.isEdit = true;
				_this.entity = res;
				_this.openWindow('特殊名单查看');
			}, true);
		},
		openWindow : function ( title ) {
			var _this = this;
			_this.editDiv = _this.sysUtils.openWindow(_this.editDiv, {
				title : title,
				height : "265px",
				width : "660px",
				resizable : false,
				content : "views/parkLotCenter/accessRights/blackAndWhite_Edit.html",
			}, true);
		},
		deleteAccess : function (e) {
			var _this = this;
			if (!isEmpty(e)) {
				_this = $(e.target).data('that');
			}
			var ids = '';
			_this.$parent.find('input[name="blackWhiteId"]:checked').each(function (inx, itm) {
				ids += $(itm).val() + SEPARATOR;
			});
			if (isEmpty(ids)) {
				notification({title : '提示', message : '请勾选中需要删除的数据'}, 'info');
				return;
			}
			ids = ids.substring(0, ids.length - 1);
			notification({title : '提示', message : '是否确认删除勾选信息？此操作无法撤销'}, 'confirm', {
				callback : function () {
					JsonpAjax(baseApiPath + 'blackAndWhite/deleteByIds', ids, 'json', function ( res ) {
						_this.findData();
					}, true);
				}
			})
		},
		/**
		 * 资料导入
		 * @param e
		 */
		importInfo:function(e){
			this.editDiv = this.sysUtils.openWindow(this.editDiv, {
				title : "特殊名单信息导入",
				height : "650px",
				width : "600px",
				resizable : false,
				content : "views/parkLotCenter/accessRights/blackUpLoad.html",
				open:function(e){
					//页面加载完成后初始化导入对象
				}
			}, true);
		}
};

var blackAndWhiteEditJs = function ($parent) {
	this.$parent = $parent;
	this.sysUtils = new kendoUtils();
	this.init();
	return this;
};
blackAndWhiteEditJs.prototype = {
		init : function () {
			var _this = this;
			var fieldArray = this.sysUtils.getBindFieldArray(this.$parent);
			var functionArray = [
			                     {fName : 'save_info', fs : _this.saveInfo},
			                     {fName : 'cancel', fs : closeWindow}
			                     ];
			this.models = new bindBaseModel(null, fieldArray, functionArray, null);
			this.sysUtils.bindDoucment(this.models, this.$parent, this);
			Utils.createDataDictDropDownList([{div:this.$parent.find('#dataType'), parentModelKey:BASIS.SPECIAL_TYPE.ROOT, select:Utils.getModelValueByModelKey(BASIS.SPECIAL_TYPE.SPECIAL_TYPE_WHITE)},
			                                  {div:this.$parent.find("#takeUpSpaces"),parentModelKey:BASIS.BOTT_LEVEL_ROOT.ROOT,select:Utils.getModelValueByModelKey(BASIS.BOTT_LEVEL_ROOT.BOTT_LEVEL_N)}], this);
			if (blackWhiteJs.isEdit == true && !isEmpty(blackWhiteJs.entity)) {
				_this.sysUtils.setBindFieldValue(blackWhiteJs.entity);
				_this.$parent.find("input,textarea").prop("disabled","disabled");
				_this.$parent.find("#dataType").data("kendoDropDownList").enable(false);
				_this.$parent.find("#takeUpSpaces").data("kendoDropDownList").enable(false);
				_this.$parent.find(".basicInfo-btn").empty();
			}
		},
		saveInfo : function (e) {
			var _this = this;
			if (!isEmpty(e)) {
				_this = $(e.target).data('that');
			}
			if (validityForm(_this.$parent)) {
				var params = _this.sysUtils.getBindDocJson();
				if(params["dataType"]==Utils.getModelValueByModelKey(BASIS.SPECIAL_TYPE.SPECIAL_TYPE_BLACK)){   //黑名单
					if(isEmpty(params["remark"])){   //黑名单强制输入原因
						notification({title : '提示', message : '黑名单请输入原因！！'}, 'info');
						return;
					}
				}
				JsonpAjax(baseApiPath + 'blackAndWhite/save', JSON.stringify(params), 'json', function (res) {
					blackWhiteJs.findData();
					$('#' + blackWhiteJs.editDiv).data('kendoWindow').close();
				}, true);
			}
		}
}